//
// ExceptionInterceptionTest.m
// Copyright 2010 Mark Buer
//
// This file is part of zc-aspect.
//
// zc-aspect is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// zc-aspect is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with zc-aspect.  If not, see <http://www.gnu.org/licenses/>.
//

#import "ExceptionInterceptionTest.h"
#import "ZCAspect.h"
#import "MethodsThrowingExceptions.h"


@interface ExceptionInterceptionTest ()

@property (assign, nonatomic) BOOL didInterceptException;

@end



@implementation ExceptionInterceptionTest

@synthesize didInterceptException;


#pragma mark -
#pragma mark Test Initialisation


- (void)setUp {
	[ZCInterceptionManager interceptMethod:class_getInstanceMethod(self.class, @selector(throwsException)) withInterceptor:self];
	didInterceptException = NO;
}


#pragma mark -
#pragma mark Interceptor(Delegate) TODO Fix my name!


- (void)interceptInvocation:(Invocation *)invocation {
	@try {
		invocation_invoke(invocation);
	}
	@catch (NSException *e) {
		didInterceptException = YES;
	}
}


#pragma mark -
#pragma mark Test-subject Method


- (void)throwsException {
	@throw [NSException exceptionWithName:@"TestException" reason:@"Who needs one?" userInfo:nil];
}


#pragma mark -
#pragma mark Test Methods


- (void)testExceptionPropogation {
	STAssertNoThrow([self throwsException], nil);
    STAssertTrue(didInterceptException, nil);
}


@end
